﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ERPStore.NewsLetters.Services;

namespace ERPStore.NewsLetters.Tests.Services
{
	public class TestRecipientSourceProvider : IEmailListSourceProvider
	{
		private IList<Models.EmailRecipient> m_List;

		public TestRecipientSourceProvider(ERPStore.NewsLetters.Services.NewsLettersService newsLetterService)
		{
			this.NewsLetterService = newsLetterService;
		}

		protected ERPStore.NewsLetters.Services.NewsLettersService NewsLetterService { get; set; }

		#region IEmailListSourceProvider Members

		public string SourceTypeId
		{
			get { return "69EFEC43-EFA8-409B-85DA-C107442F65EC"; }
		}

		public string DisplayName
		{
			get { return "test"; }
		}

		public void Initialize(Models.EmailListSource source)
		{
			m_List = new List<Models.EmailRecipient>();
			for (int i = 0; i < 200; i++)
			{
				var emailTest = string.Format("{0}@test.com", Guid.NewGuid().ToString());

				var rcp = new Models.EmailRecipient()
				{
					Email = emailTest,
					FullName = "test",
				};
				NewsLetterService.SaveEmailRecipient(rcp);

				m_List.Add(rcp);
			}
		}

		public IEnumerable<Models.EmailRecipient> GetList(int pageIndex, int pageSize, out int count)
		{
			count = m_List.Count;
			return m_List.Skip(pageIndex * pageSize).Take(pageSize).ToList();	
		}

		public IList<ERPStore.Models.BrokenRule> Validate()
		{
			return null;
		}

		public string GetSerializedSettings()
		{
			return "test";
		}

		#endregion
	}
}
